package edu.scau.divineplace.controller;

import edu.scau.divineplace.config.global.log.WebLog;
import edu.scau.divineplace.entity.enums.RoleTypeEnum;
import edu.scau.divineplace.entity.query.PageQuery;
import edu.scau.divineplace.entity.vo.banword.BanWordVO;
import edu.scau.divineplace.entity.vo.content.RoleVO;
import edu.scau.divineplace.service.BanWordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author: x1aolone
 * @Date: 2021/2/9 14:57
 */
@Slf4j
@RestController
@CrossOrigin
@Api("BanWord控制器")
@WebLog("BanWord控制器")
@Validated
@RequestMapping("/banWord")
public class BanWordController {

    @Autowired
    private BanWordService banWordService;

    @ApiOperation("获取违禁词列表")
    @GetMapping("/list")
    public List<BanWordVO> list(String word, PageQuery pageQuery) {
        return banWordService.list(word, pageQuery);
    }

    @ApiOperation("新增违禁词")
    @PostMapping
    public int upload(@NotBlank String word) {
        return banWordService.upload(word);
    }

    @ApiOperation("修改违禁词")
    @PutMapping
    public int update(@NotNull Long id, @NotBlank String word) {
        return banWordService.update(id, word);
    }

    @ApiOperation("根据id删除违禁词")
    @DeleteMapping()
    public int delete(@NotNull Long id) {
        return banWordService.delete(id);
    }

}
